package types

import (
	"database/sql/driver"
	"encoding/json"
)

func Scan(src interface{}, dst interface{}) error {
	var source string
	switch src.(type) {
	case string:
		source = src.(string)
	case []byte:
		source = string(src.([]byte))
	}
	return json.Unmarshal([]byte(source), dst)
}
func Value(dst interface{}) (driver.Value, error) {
	v := ""
	if dst != nil {
		bt, e := json.Marshal(dst)
		if e != nil {
			return nil, e
		}
		v = string(bt)
	}
	return driver.Value(v), nil
}
